package com.module.skin;

import android.content.Context;

import java.io.File;

import skin.support.load.SkinSDCardLoader;

public class CustomSDCardLoader extends SkinSDCardLoader {
    public static final int SKIN_LOADER_STRATEGY_SDCARD = Integer.MAX_VALUE;

    private String skinPath;

    public CustomSDCardLoader(String skinPath) {
        this.skinPath = skinPath;
    }

    @Override
    protected String getSkinPath(Context context, String skinName) {
        if (skinName.endsWith(".skin")) {
            return getPath(skinPath, skinName);
        } else {
            return getPath(skinPath, skinName + ".skin");
        }
    }

    @Override
    public int getType() {
        return SKIN_LOADER_STRATEGY_SDCARD;
    }


    /**
     * 获取skin路径
     */
    public String getPath(String parent, String child) {
        File appDir = new File(parent, child);
        if (!appDir.exists()) {
            return null;
        }
        return appDir.getAbsolutePath();
    }
}
